<?php /** 获取题库列表 api **/
require_once '../../config/req.conf.php';
require_once '../../utils/CommonMethods.php';
require_once '../../utils/VerifyFormData.php';
require_once '../../utils/DBUtils.php';

/* 1. token认证和角色权限校验 */
$headers = apache_request_headers(); // 请求头信息获取
$info = VerifyFormData::verifyRole($headers['Authorization'], "root");
if( CommonMethods::isEmpty($info) ){
    RespJson::fail("没有访问权限");
    return;
}

/* 2. 获取题库数据信息 */
DBUtils::init();
$result = DBUtils::queryMulti(DBUtils::getSql("php_questions")->filter("id, question, type")->select());
if( CommonMethods::isEmpty($result) ){
    RespJson::fail("数据获取失败, 请刷新重试");
    return;
}
//foreach ($result as $index => $item ){
//    foreach ($item as $key => $value){
//        if( $key === 'type' ){
//            if( $value === 'radio' ){
//                $result[$index]['type'] = "单选题";
//            }else if( $value === 'multi' ){
//                $result[$index]['type'] = "多选题";
//            }else if( $value === 'judge' ){
//                $result[$index]['type'] = "判断题";
//            }
//        }
//    }
//}

/* 3. 返回数据 */
RespJson::success($result);
